﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Shop.MVC.Controllers
{
    public class UploadController : Controller
    {
        // GET: Upload
        public ActionResult Index(HttpPostedFileBase file)
        {
            string[] allows = { "jpg", "png", "gif" };
            var extName = file.FileName.Split('.')[1];
            if(allows.Contains(extName) )
            {
                var name=Guid.NewGuid().ToString()+"."+extName;
                var path = "/uploads/" + name;
                file.SaveAs(Server.MapPath(path));
                return Json(new { success = true, msg = "上传成功！", data = path });
            }
            return Json(new { success = false, msg = "格式不允许！" });
            
        }
    }
}